#ifndef SESSION_COMMAND_IN_H_
#define SESSION_COMMAND_IN_H_
#include "command.h"

#pragma pack(1)
namespace Cmd
{
        namespace Session
        {
                //  cmd declaration
                enum {
                        CMDIN_LOGIN             = 0x0010,	// 登录SessionServer验证指令
                        CMDIN_FORWARD           = 0x0011,	// 转发的指令
                        CMDIN_GATEWAY           = 0x0012,	// 与GatewayServer交互的指令
                };
                //  sub cmd declaration
                enum { //CMDIN_LOGIN
                        SCMDIN_LOGIN                            = 0x0001,       // 请求登录SessionServer
                        SCMDIN_LOGIN_RESPONSE                   = 0x0002,	// 登录SessionServer返回
                };
                enum { //CMDIN_FORWARD
                        SCMDIN_FORWARD                          = 0x0001,       // 转发到SessionServer的指令
                        SCMDIN_FORWARD_USER                     = 0x0002,	// SessionServer转发指令给用户
                        SCMDIN_FORWARD_BETTWEN_SESSION          = 0x0003,	// Session->Gateway->Session:转发用户消息到另一个Session
                };
                enum { //CMDIN_GATEWAY
                        SCMDIN_GATEWAY_REGIST_USER              = 0x0001,	// Gateway->Session:用户登录
                        SCMDIN_GATEWAY_RETURN_REGIST_USER       = 0x0002,	// Session->Gateway:返回用户登录结果
                        SCMDIN_GATEWAY_REQ_UNREGIST_USER        = 0x0003,
                        SCMDIN_GATEWAY_REQ_SESSION_LOAD         = 0x0004,
                        SCMDIN_GATEWAY_RES_SESSION_LOAD         = 0x0005,
                        SCMDIN_GATEWAY_GLOBAL_USER_ADD_OLD      = 0x0006,	// Gateway->Sessi0n:通知所有session增加global用户
                        SCMDIN_GATEWAY_GLOBAL_USER_DEL          = 0x0007,	// Gateway->Session:通知所有session移除global用户
                        SCMDIN_GATEWAY_SYNC_GW_USERLIST         = 0x0008,	// Session->Gateway:session启动时请求网关上的所用用户列表
                        SCMDIN_GATEWAY_SYNC_GW_USERLIST_RES_OLD = 0x0009,       // Gateway->session:Gateway发送本服务器上的用户列表给SessionServer
                        SCMDIN_GATEWAY_UPDATE_USER_ROOM         = 0x000A,	// Session->Gateway:Session通知Gateway用户的当前所在房间
                        SCMDIN_GATEWAY_BROAD_ROOM_CMD           = 0x000B,	// Session->Gateway:session转发指令到所有网关，网关根据roomid发送指令到用户
                        SCMDIN_GATEWAY_REQ_CURRENT_ROOM         = 0x000C,       // Session->Gateway:session向gateway请求恢复用户当前所在room
                        SCMDIN_GATEWAY_RES_CURRENT_ROOM         = 0x000D,       // Gateway->Session:gateway返回给session当前所在的room
                        SCMDIN_GATEWAY_KICKOFF_USER             = 0x000E,       // Session->Gateway:session通知Gateway用户被踢下线
                        SCMDIN_GATEWAY_KICKOFF_USER_2           = 0x000F,       // Session->Gateway:session通知Gateway用户被踢下线
                        SCMDIN_GATEWAY_GLOBAL_USER_ADD          = 0x0010,	// Gateway->Sessi0n:通知所有session增加global用户
                        SCMDIN_GATEWAY_SYNC_GW_USERLIST_RES     = 0x0011,	// Gateway->session:Gateway发送本服务器上的用户列表给SessionServer
                        SCMDIN_GATEWAY_REGIST_USER_UNIFIED      = 0x0012,       // Gateway->Session:统一用户登录
                        SCMDIN_GATEWAY_UNREGIST_USER_UNIFIED    = 0x0013,       // Session->Gateway:session启动时请求网关上的所用用户列表
                        SCMDIN_GATEWAY_RESET_UNREGISTERED       = 0x0014,       // Gateway->Session:通知重置未注册用户帐号
                };

                //	cmd definition
                struct stLoginCmd:t_NullCmd
                {
                        stLoginCmd():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN)
                        {
                                dest_type_ = SESSIONSERVER;
                                server_type_ = 0;
                                server_id_ = 0;
                        }
                        WORD dest_type_;
                        WORD server_type_;
                        DWORD server_id_;
                };
                struct stLoginResponce:t_NullCmd
                {
                        stLoginResponce():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN_RESPONSE)
                        {
                        }
                };

                struct stForwardCmd:t_NullCmd
                {
                        stForwardCmd():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD)
                        {
                                user_id_ = 0;
                                size_ = 0;
                        }
                        DWORD user_id_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() const
                        {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stForwardUser:t_NullCmd
                {
                        stForwardUser():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_USER)
                        {
                                user_id_ = 0;
                                size_ = 0;
                        }
                        DWORD user_id_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() const
                        {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stForwardBettwenSession:t_NullCmd
                {
                        stForwardBettwenSession():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_BETTWEN_SESSION)
                        {
                                session_from_ = 0;
                                session_to_   = 0;
                                size_ = 0;
                        }
                        WORD session_from_;
                        WORD session_to_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize()
                        {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };

                struct stGatewayRegistUser:
                        t_NullCmd
                {
                        stGatewayRegistUser():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_REGIST_USER)
                        {
                                user_id_ = 0;
                                ip_ = 0;
                                mac_ = 0;
                                version_ = 0;
                                net_ = 0;
                                rereg_ = 0;
                                terminal_ = eTerminalType_pc;
                                cmd_version_ = 0;
                                os_ = 0;
                        }
                        DWORD user_id_;
                        DWORD ip_;
                        QWORD mac_;
                        DWORD version_;
                        WORD  net_;     //0-dianxin 1-liantong
                        BYTE  rereg_;   //reregist user for session crush: 0-no,1-yes.
                        BYTE  terminal_;//eTerminalType
                        DWORD cmd_version_;
                        BYTE os_;       // eOSType
                        //...
                };

                struct stGatewayRegistUserUnified :
                        t_NullCmd
                {
                        stGatewayRegistUserUnified() :
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_REGIST_USER_UNIFIED)
                        {
                                user_id_ = 0;
                                ip_ = 0;
                                version_ = 0;
                                net_ = 0;
                                rereg_ = 0;
                                cmd_version_ = 0;    
                                login_flags_ = eUserLoginType_null;
                                size_ = 0;
                        }
                        uint32_t user_id_;
                        uint32_t ip_;
                        uint32_t version_;
                        uint16_t  net_;     //0-dianxin 1-liantong
                        uint8_t  rereg_;   //reregist user for session shutdown: 0-no,1-yes.                        
                        uint32_t cmd_version_;
                        uint32_t login_flags_;  // 登录标志, 参考 eUserLoginType
                        uint16_t size_;            // json字符串长度
                        char extra_info_[0];   // json格式

                        DWORD getSize() const
                        {
                                return (sizeof(*this) + size_);
                        }

                        /* extera_info example:
                        {"dvt":3,  // device type
                        "ost":4,  // os type
                        "dvi":"abcdefg",  //device id
                        "mac":"abcdefg",  // mac
                        "bra":"ipad",  // brand
                        "svn":"1.0",  // sdk version
                        "mob":"1234567890",  // phone number
                        "avn":"1.0"  // app version
                        }
                        */
                };

                struct stGatewayReturnRegistUser:
                        t_NullCmd
                {
                        stGatewayReturnRegistUser():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_RETURN_REGIST_USER)
                        {
                                user_id_ = 0;
                                rereg_ = 0;
                                ret_code_ = 0;
                        }
                        DWORD user_id_;
                        BYTE rereg_;    //宕机恢复导致的重新注册: 0-no 1-yes
                        BYTE ret_code_; //0-fail, 1-success, 2-ip forbidden, 3-mac forbidden, 4-version forbidden
                };

                struct stGatewayReqUnRegistUser:
                        t_NullCmd
                {
                        stGatewayReqUnRegistUser():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_REQ_UNREGIST_USER)
                        {
                                user_id_ = 0;
                        }
                        DWORD user_id_;
                        DWORD reason_;
                };

                struct stGatewayUnregistUserUnified:
                        t_NullCmd
                {
                        stGatewayUnregistUserUnified():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_UNREGIST_USER_UNIFIED)
                        {
                                user_id_ = 0;
                        }

                        uint32_t user_id_;
                        uint32_t login_flags_;          // 登录标志, 参考 eUserLoginType
                        uint32_t reason_;
                };

                struct stGatewayReqSessionLoad:
                        t_NullCmd
                {
                        stGatewayReqSessionLoad():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_REQ_SESSION_LOAD)
                        {
                        }
                };
                struct stGatewayResSessionLoad:
                        t_NullCmd
                {
                        stGatewayResSessionLoad():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_RES_SESSION_LOAD)
                        {
                                load_ = 0;
                        }
                        DWORD load_;
                };
                struct stGatewayGlobleUserAddOld:
                        t_NullCmd
                {
                        stGatewayGlobleUserAddOld():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_GLOBAL_USER_ADD_OLD)
                        {
                                user_id_ = 0;
                                session_id_ = 0;
                        }
                        DWORD user_id_;
                        WORD session_id_;
                };
                struct stGatewayGlobleUserDel:
                        t_NullCmd
                {
                        stGatewayGlobleUserDel():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_GLOBAL_USER_DEL)
                        {
                                user_id_ = 0;
                                session_id_ = 0;
                        }
                        DWORD user_id_;
                        WORD session_id_;
                };
                struct stGatewaySyncGWUserList:
                        t_NullCmd
                {
                        stGatewaySyncGWUserList():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_SYNC_GW_USERLIST)
                        {
                        }
                };
                struct stGatewaySyncGWUserListResOld:
                        t_NullCmd
                {
                        stGatewaySyncGWUserListResOld():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_SYNC_GW_USERLIST_RES_OLD)
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct {
                                DWORD userid;
                                WORD sessionid;
                        }list_[0];
                        DWORD getSize()
                        {
                                return sizeof(*this)+size_*sizeof(list_[0]);
                        }
                };
                struct stGatewayUpdateUserRoom:
                        t_NullCmd
                {
                        stGatewayUpdateUserRoom():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_UPDATE_USER_ROOM)
                        {
                                user_id_ = 0;
                                room_id_ = 0;
                        }
                        DWORD user_id_;
                        DWORD room_id_;
                };
                struct stGatewayBroadRoomCmd:
                        t_NullCmd
                {
                        stGatewayBroadRoomCmd():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_BROAD_ROOM_CMD)
                        {
                                room_id_ = 0;
                                except_user_ = 0;
                                size_ = 0;
                        }
                        DWORD room_id_;
                        DWORD except_user_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() const
                        {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stGatewayReqCurrentRoom:
                        t_NullCmd
                {
                        stGatewayReqCurrentRoom():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_REQ_CURRENT_ROOM)
                        {
                                user_id_ = 0;
                        }
                        DWORD user_id_;
                };
                struct stGatewayResCurrentRoom:
                        t_NullCmd
                {
                        stGatewayResCurrentRoom():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_RES_CURRENT_ROOM)
                        {
                                user_id_ = 0;
                                room_id_ = 0;
                        }
                        DWORD user_id_;
                        DWORD room_id_;
                };
                struct stGatewayKickoffUser:
                        t_NullCmd
                {
                        stGatewayKickoffUser():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_KICKOFF_USER)
                        {
                                user_id_ = 0;
                                reason_ = eLogoutReason_null;
                        }
                        DWORD user_id_;
                        BYTE reason_; //eLogoutReason
                };
                struct stGatewayKickoffUser2:
                        t_NullCmd
                {
                        stGatewayKickoffUser2():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_KICKOFF_USER_2)
                        {
                                user_id_ = 0;
                                minutes_ = 0;
                                bzero(reason_, sizeof(reason_));
                        }
                        DWORD user_id_;
                        DWORD minutes_; //minutes_分钟之后可以登录
                        char reason_[256];
                        
                };
                struct stGatewayGlobleUserAdd:
                        t_NullCmd
                {
                        stGatewayGlobleUserAdd():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_GLOBAL_USER_ADD)
                        {
                                user_id_ = 0;
                                session_id_ = 0;
                                status_  = USER_STATE_ONLINE;
                        }
                        DWORD user_id_;
                        WORD session_id_;
                        BYTE status_;
                };
                struct stGatewaySyncGWUserListRes:
                        t_NullCmd
                {
                        stGatewaySyncGWUserListRes():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_SYNC_GW_USERLIST_RES)
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct {
                                DWORD userid;
                                WORD sessionid;
                                BYTE status;
                        }list_[0];
                        DWORD getSize()
                        {
                                return sizeof(*this)+size_*sizeof(list_[0]);
                        }
                };
                struct stGatewayResetUnregistered:
                        t_NullCmd
                {
                        stGatewayResetUnregistered():
                                t_NullCmd(CMDIN_GATEWAY, SCMDIN_GATEWAY_RESET_UNREGISTERED)
                        {
                                user_id_ = 0;
                        }

                        uint32_t user_id_;
                };
        }; //namespace Record
}; //namespace Cmd
#pragma pack() //pack(1)

#endif //SESSION_COMMAND_H_
